<a href=" 正则表达式 请高手帮忙写一下,除去http:

来源:百度知道 编辑:UC知道 时间:2024/06/07 19:36:39
从网页中提取 <a href=" 的正则表达式 请高手帮忙写一下,除去http:结尾的.
急75分等答案
http是接的网址.

我想找出超连接,但是不找含有网址的超连接.
只找相对路经的超联接.

网页中有 <a href="index.html
<a href="class.html
<a href="http://www.baidu.com

现在要找出 <a href="index.html
<a href="class.html
替换成
<a href="../index.html
<a href="../class.html

在EmEditor下测试通过:
正则式: <a href="(?=.*?\.html)
替换为: <a href="../

测试文本:
<a href="index.html
<a href="class.html
<a href="http://www.baidu.com

测试结果:
<a href="../index.html
<a href="../class.html
<a href="http://www.baidu.com

其实完全可以写成:(?<=<a href=")(?=.*?\.html)
但是EmEditor不支持(?<=pattern)的语法。

<a href=".*?">

http:结尾的是什么意思?

2楼
你那个有个小bug
如果是 http://www.baidu.com/a.html
就不行了

改进了下
正则 <a href="(((?!http).)+) 替换成 <a href="../$1